package com.control;

import com.dao.StudentDao;
import com.dao.UserDao;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author :wn
 * @program : 项目五登录界面
 * @descript : 添加学生的servlet类
 * @create :2020-11-07 23:16
 */
@WebServlet(value = "/addStudent")
public class addToStudentConstrol extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name=new String (req.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
        String age=new String (req.getParameter("age").getBytes("ISO-8859-1"),"UTF-8");
        String sex=new String (req.getParameter("sex").getBytes("ISO-8859-1"),"UTF-8");
        String sdept=new String (req.getParameter("sdept").getBytes("ISO-8859-1"),"UTF-8");
        try {
            boolean addStudent=new StudentDao().addWay(name,age,sex,sdept);
            if(addStudent){
                String addInformation="添加成功";
                req.setAttribute("addInformation",addInformation);
                req.getRequestDispatcher("/addInterface.jsp").forward(req,resp);
            }else {
                String  addInformation="添加失败";
                req.setAttribute("addInformation",addInformation);
                req.getRequestDispatcher("/addInterface.jsp").forward(req,resp);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}
